package com.qfedu.fy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.fy.dao.TeacherDao;
import com.qfedu.fy.dao.UserDao;
import com.qfedu.fy.entity.Teacher;
import com.qfedu.fy.entity.User;
import com.qfedu.fy.service.intf.TeacherService;
import com.qfedu.fy.service.intf.UserService;
import com.qfedu.fy.vo.PageBeanVo;
import com.qfedu.fy.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * ......................我佛慈悲......................
 * _oo0oo_
 * o8888888o
 * 88" . "88
 * (| -_- |)
 * 0\  =  /0
 * ___/`---'\___
 * .' \\|     |// '.
 * / \\|||  :  |||// \
 * / _||||| -卍-|||||- \
 * |   | \\\  -  /// |   |
 * | \_|  ''\---/''  |_/ |
 * \  .-\__  '-'  ___/-. /
 * ___'. .'  /--.--\  `. .'___
 * ."" '<  `.___\_<|>_/___.' >' "".
 * | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 * \  \ `_.   \_ __\ /__ _/   .-` /  /
 * =====`-.____`.___ \_____/___.-`___.-'=====
 * `=---='
 * ..............佛祖保佑无BUG..................
 *
 * @author mxj
 * @date 2022/6/16 20:30
 */
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherDao dao;

    @Override
    public R add(Teacher teacher) {

        if(dao.add(teacher)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBeanVo selectAll(int page,int limit) {
        //1.开启分页
        PageHelper.startPage(page, limit);
        //2.获取查询的结果
        PageInfo<Teacher> pageInfo=new PageInfo<>(dao.selectAll());
        //3.返回结果
        return new PageBeanVo(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public R update(Teacher teacher) {
        if(dao.update(teacher)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R del(int id) {
        if(dao.del(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }
}
